package com.imooc.spark

import org.apache.spark.sql.SparkSession

/**
  * Parquet文件操作
  */
object ParquetApp {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder().appName("DataFrameRDDApp").master("local[2]").getOrCreate()
    val userDF = spark.read.format("parquet").load("src/main/resources/users.parquet")
    //spark.read.format("parquet").option("path","").load()
    //userDF.show()

    userDF.select(userDF.col("name"),userDF.col("favorite_color"))
      .write.format("json").save("src/main/resources/save/users")

    spark.sql("CREATE TEMPORARY VIEW parquetTable USING org.apache.spark.sql.parquet OPTIONS (path \"src/main/resources/users.parquet\")")

    spark.sql("select * from parquetTable").show()

    spark.stop()
  }
}
